
pro help_menu, uvalue
common slugs, status
case uvalue of
'help_seed': helptext=['The seed determines the exact distribution of',$
                      'random numbers. To reproduce the identical sequence',$
	              'of random numbers, use the same seed. Setting the',$
		      'seed to 0 tells the code to use the machine time as',$
		      'the seed. This is the recommended and default choice.']

'help_imf':	helptext=['Select the type of IMF you want to use']
'help_imfslope': helptext=['This paramter only has meaning if you',$
		           'have chosen the SLOPE IMF type. In that ',$
			   'case it sets the power law',$
			    'slope of the IMF. ']
'help_tracks':  helptext=['Select the stellar evolutionary tracks',$
			  'that you wish to use, described in',$
			  'da Silva et al. 2011.']
'help_sed':     helptext=['Select the SED model you wish to use',$
			  'described in da Silva et al. 2011.']
'help_wind':	helptext=['Select the wind model you wish to use',$
			  'described in da Silva et al. 2011.']
'help_clusfrac':helptext=['Set the mass fraction of stars that you',$
			  'wish to form in clusters. Unclustered ',$
			  'star formation runs slower']
'help_feh':	helptext=['Select the metallicity of stars you want',$
			  'to use. Solar Metallicty in these units',$
			  'is 0.020']
'help_draw':	helptext=['The code uses one of two algorithms to',$
			  'determine stellar ages. We recommend',$
			  'the random method']
'help_maxmass': helptext=['This sets the maximum mass [in units of',$
			  'Msun] for the Cluster Mass function.',$
			  'If the IGIMF is selected, this parameter',$
			  'instead determines the ineterval [in years]',$
			  'over which to average the SFR in order to ',$
			  'determine the maximum cluster mass'	]
'help_minmass':helptext=['This sets the minimum mass [in units of',$
                          'Msun] for the Cluster Mass function']
'help_cmfslope':helptext=['This sets the power law index for the',$
			  'Cluster Mass Function. -2 is preferred.']
'help_sfh':	helptext=['Set the SFH of your model. Input either a number',$
			  'which will be interpreted as a constant SFH or ',$
			  'a file name which will be interpreted as a file from',$
			  'which to read the SFH in the format described in the',$
			  'the manual. You can interactively create your own SFH',$
			  'and SFH file by selecting the Make button. If you do so',$
			  'here are the command for that window. ',$
			  'mouse wheel: zoom in and out of y axis',$
			  'right mouse button: click and drag near a point',$
			  '       to move it',$
			  'the letter d near a point: to remove it']
'help_clusout':helptext=['Select to enable output for each cluster']
'help_imfout':helptext=['Select to enable IMF histogram output for each cluster']
'help_name':	helptext=['Name a model a unique name. Do not use spaces or',$
			  'periods. If you do not rename your model, it will',$
			  'overwrite the previous one']
'help_timestep':helptext=['The timestep of code printouts. Setting this to a smaller',$
			  'number gives more time resolution but increases computation',$
			  'time. Given in units of yr']
'help_maxtime': helptext=['Set how long you want the simulation to run. In units of yr']
'help_fluxes':  helptext=['Select the fluxes you want printed out. More fluxes',$
			  'result in longer computation time.']
'help_colormag': helptext=['You need at least 2 fluxes chosen to make a color magnitude ',$
			   'diagram']
'help_addcolormag': helptext=['Set parameters for each color mag diagram']
'help_running':helptext=['Run Process:     Push this to run the model whose parameters you input',$
			 'View Param File: Push this to view the .param file. For information see',$
			 '                 documentation', $
			 'Copy Process:    Copy the input parameters of the selected process to the GUI',$
			 'Grid Process:    A tool for running grid jobs [disabled]',$
			 'Kill Process:    Kill an ongoing process [disabled]']			
else:
endcase
;now draw the help menu
if keyword_set(helptext) then rds_popup, status.tlb, text=helptext


end

;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
pro write_status
common slugs, status
common btns, imfbtn, fehbtn
common cmagcom, cmagnew, cmagold
common refs, fehlistid, sedlistid, windlistid, trbtn

if status.cmagson GT 0 then begin
if keyword_set(cmagold) then begin
status.colorchoice=strjoin(cmagold.f1+cmagold.f2, ',')
status.binflux=strjoin(cmagold.binflux, ',')
status.minflux=strjoin(cmagold.minflux, ',')
status.maxflux=strjoin(cmagold.maxflux, ',')
status.bincolor=strjoin(cmagold.bincolor, ',')
status.mincolor=strjoin(cmagold.mincolor, ',')
status.maxcolor=strjoin(cmagold.maxcolor, ',')
endif
endif else begin
status.colorchoice=''
endelse




fluxnames=['NUV','FUV','BOL','J','H','K','SDSSu','SDSSg','SDSSr','SDSSi','SDSSz',$
	'johnsonU','johnsonB','johnsonV','johnsonR','johnsonI', 'QH0']
wh=where(status.fluxes GT 0)
status.flux_choice=strjoin(fluxnames[wh], ',')
if status.cmagson LT 0 then begin
status.binflux='2'
status.bincolor='2'
status.colorchoice=fluxnames[wh[0]]+'-'+fluxnames[wh[0]]
endif
metname=(strsplit((fehlistid->getselection()) , '.', /extract))
if n_elements(metname) GT 1 then metname=metname[1]

libpath='/iso/'+status.trackchoice+'/'+metname+'/'+sedlistid->getselection()+'/'+windlistid->getselection()+'/'


drive_slug, model_name=status.modelname, timestep=status.timestep,$
	maxtime=status.maxtime, galaxy_sfr=status.sfr, galaxy_sfh=status.sfh,$
	imf_type=status.imfchoice, libpath=libpath,$
	imf_slope=status.imf_slope, max_cluster_mass=status.maxclustermass,$
	min_cluster_mass=status.minclustermass,$
	slope_cmf=status.slopecmf, drawtype=status.drawchoice,$
	fluxes=status.flux_choice, colors=status.colorchoice,$
	binflux=status.binflux, bincolor=status.bincolor,$
	maxcolor=status.maxcolor, mincolor=status.mincolor,$
	minflux=status.minflux, maxflux=status.maxflux,$
	imfout=status.imfout, outcluster=status.outcluster,$
	clust_frac=status.clust_frac,	seed=status.seed,/dry

end
;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
pro gui_refresh
common slugs, status
common btns, imfbtn, fehbtn
common refs, fehlistid, sedlistid, windlistid, trbtn
fehlistid->setselection, status.fehchoice
;imflistid->setselection, status.imfchoice
sedlistid->setselection, status.sedchoice
windlistid->setselection,status.wind_choice
trbtn->setselection, status.trackchoice
imfbtn->setindex, where(strmatch(status.imfnames, '*'+status.imfchoice+'*'))
;fehbtn->setindex, where(strmatch(status.fehnames, '*'+status.fehchoice+'*'))
if strmatch(status.drawchoice, '*random*',/fold) then widget_control, status.drawbtns[0], /set_button
if strmatch(status.drawchoice, '*seq*',/fold) then widget_control, status.drawbtns[1], /set_button
widget_control, status.cmfmaxbtn, set_value=status.maxclustermass
widget_control, status.cmfminbtn, set_value=status.minclustermass
widget_control, status.cmfslopebtn, set_value=status.slopecmf
if status.sfr GT 0 then widget_control, status.sfhbtn , set_value=status.sfr else $
             widget_control, status.sfhbtn , set_value=status.sfh
widget_control,status.outnamebtn , set_value=status.modelname
widget_control,status.timestepbtn , set_value=status.timestep
widget_control,status.maxtimebtn , set_value=status.maxtime

widget_control, status.seedbtn, set_value=status.seed

widget_control, status.clusfracbtn, set_value=status.clust_frac
if strmatch(status.outcluster,'*yes*') then $
	widget_control, status.coutbtny, /set_button $
	else widget_control, status.coutbtnn, /set_button

if strmatch(status.imfout,'*yes*') then widget_control, status.ioutbtny, /set_button $
	else widget_control, status.ioutbtnn, /set_button

names=[	'nuv','fuv','bol','QH0','j','h','k',$
	'SDSSu','SDSSg','SDSSr',$
	'SDSSi','SDSSz','johnsonU','johnsonB','johnsonV',$
	'johnsonR','johnsonI']
status.fluxes=-1
split=strcompress(strsplit(status.flux_choice, ',',/extract), /remove_all)
for i=0, n_elements(names)-1 do begin
	widget_control, status.fluxesbtn[i], set_button=0
  for j=0, n_elements(split)-1 do begin
  if strmatch(split[j], names[i], /fold) then begin
	status.fluxes[i]*=-1
	widget_control, status.fluxesbtn[i], /set_button
  endif
  endfor
endfor




end
;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
pro parse_param, filename
common slugs, status
common btns, imfbtn, fehbtn
common cmagcom, cmagnew, cmagold
openr, lun, filename, /get_lun
dum=''
dumarr=''
  while ~EOF(lun) do begin
    readf, lun, dum
    dumarr=[dumarr, dum]
  endwhile
close, lun

wh=where(strmatch(dumarr, '#*') EQ 0 AND strmatch(dumarr, '') EQ 0)
dumarr=dumarr[wh]
status.timestep='2E6'
status.maxtime='1E9'
status.sfr='1'
status.sfh='mysfh.txt'
status.imfchoice='KROUPA'
status.imf_slope='-2.35'
status.fehchoice='0.020'
status.sedchoice='lej+smi'
status.wind_choice='maedr'
status.trackchoice='padagb'
status.maxclustermass='1E7'
status.minclustermass='20'
status.slopecmf='-2'
status.clust_frac='1.0'
status.drawchoice='RANDOM'
status.modelname='SLUG_DEF'
status.seed='0'
status.flux_choice='FUV,QH0'
status.colorchoice='FUV-QH0'
status.bincolor='2'
status.binflux='2'
status.maxcolor='20'
status.mincolor='1'
status.maxflux='50'
status.minflux='1'
status.outcluster='no'
status.imfout='no'

tagname= ['timestep', 'maxtime', 'sfr'       ,'sfh'	  ,$
		'imfchoice', 'imf_slope', 'modelname', 'maxclustermass',$
		'minclustermass', 'slopecmf', 'clust_frac', 'drawchoice',$
		'seed', 'flux_choice', 'colorchoice', 'binflux',$
		'bincolor', 'maxcolor', 'mincolor', 'maxflux', 'minflux',$
		'outcluster', 'imfout']
slugname=['timestep', 'maxtime', 'galaxy_sfr','galaxy_sfh',$
		'imf_type', 'imf_slope', 'model_name', 'max_cluster_mass',$
		'min_cluster_mass', 'slope_cmf', 'clust_frac', 'drawtype',$
		'seed', 'fluxes'     , 'colors', 'binflux',$
		'bincolor', 'maxcolor', 'mincolor', 'maxflux', 'minflux',$
		'outcluster', 'imfout']

for i=0, n_elements(wh)-1 do begin
for j=0, n_elements(tagname)-1 do begin
if strmatch(dumarr[i], '*'+slugname[j]+'*', /fold) then begin
val= (strsplit((strsplit(dumarr[i], /extract))[1],'#' , /extract))[0]
;print, tagname[j], val, j
hashify_def, status, tagname[j], val
endif
if strmatch(dumarr[i], '*libpath*', /fold) then begin
split=strsplit(dumarr[i], '/', /extract)
status.trackchoice=split[2]
status.fehchoice='0.'+split[3]
status.sedchoice=split[4]
status.wind_choice=split[5]
endif
endfor

endfor



if strmatch(status.colorchoice, '') EQ 0 then begin
split=strsplit(status.maxcolor, ',', /extract)
nsplit=n_elements(split)
cmagold=replicate({f1:'', f2:'', binflux:'200', maxflux:'50', minflux:'-50', $
                        maxcolor:'50', mincolor:'-50', bincolor:'200'}, nsplit)
cmagold.mincolor=strsplit(status.mincolor, ',', /extract)
cmagold.maxcolor=strsplit(status.maxcolor, ',', /extract)
cmagold.bincolor=strsplit(status.bincolor, ',', /extract)
cmagold.minflux=strsplit(status.minflux, ',', /extract)
cmagold.maxflux=strsplit(status.maxflux, ',', /extract)
cmagold.binflux=strsplit(status.binflux, ',', /extract)
split0=strsplit(status.colorchoice, ',', /extract)
for i=0, nsplit-1 do begin
   split1=strsplit(split0[i], '-', /extract)
   cmagold[i].f1=split1[0]
   cmagold[i].f2='-'+split1[1]
endfor
status.cmagson=1
widget_control, status.cmagon, /set_button
widget_control, status.cmagadd, sensitive=1
endif
gui_refresh

end
;-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
pro slug_event, ev
common slugs, status
common processes, proc
common sfh_name, sfh_final_name
common refs, fehlistid, sedlistid, windlistid, trbtn
widget_control, ev.id, get_uvalue=uvalue
if keyword_set(uvalue) EQ 0 then uvalue=''
case uvalue of
'imf':status.imfchoice=status.imfnames[ev.index]
'feh':status.fehchoice=status.fehnames[ev.index]
'wind':status.wind_choice=windlistid->getselection()
'sed':status.sedchoice=sedlistid->getselection()
'random':status.drawchoice='RANDOM'
'sequntial':status.drawhcoice='SEQUENTIAL'
'maxmass':begin
	widget_control, ev.id, get_value=value
	status.maxclustermass=value
	end
'minmass':status.minclustermass=ev.value
'cmfslope':status.slopecmf=ev.value
'sfh':status.sfh=ev.value
'outname':status.modelname=ev.value
'timestep':status.timestep=ev.value
'maxtime':status.maxtime=ev.value
'nuv':status.fluxes[0]*=-1
'fuv':status.fluxes[1]*=-1
'bol':status.fluxes[2]*=-1
'j':status.fluxes[3]*=-1
'h':status.fluxes[4]*=-1
'k':status.fluxes[5]*=-1
'SDSSu':status.fluxes[6]*=-1
'SDSSg':status.fluxes[7]*=-1
'SDSSr':status.fluxes[8]*=-1
'SDSSi':status.fluxes[9]*=-1
'SDSSz':status.fluxes[10]*=-1
'johnsonU':status.fluxes[11]*=-1
'johnsonB':status.fluxes[12]*=-1
'johnsonV':status.fluxes[13]*=-1
'johnsonR':status.fluxes[14]*=-1
'johnsonI':status.fluxes[15]*=-1
'QH0':status.fluxes[16]*=-1
'run':begin
	write_status
	if keyword_set(proc) EQ 0 then begin
	   proc={procs, obridge:obj_new("IDL_IDLBridge", output=''),$
				 modelname:status.modelname, status:1L, start_time:systime()}
	endif else proc=[proc, {procs, obridge:obj_new("IDL_IDLBridge", output=''), $
				modelname:status.modelname, status:1L, start_time:systime()}]
	npro=n_elements(proc)
	spawn, 'echo $SLUG_DIR', dir
	cd, current=thisdir
	;proc[npro-1].obridge->execute, 'cd, "'+thisdir+'"'
	proc[npro-1].obridge->execute, 'cd, "'+dir+'"'
	proc[npro-1].obridge->execute, $
			"spawn, '"+dir+"slug output/"+proc[npro-1].modelname+$
			".param > "+dir+$
			"/logs/"+proc[npro-1].modelname+".log '",/nowait
	status.list_of_procs[npro-1]=proc[npro-1].modelname+'     Started on '+proc[npro-1].start_time+'   Running...'
	widget_control, status.big_list, set_value=status.list_of_procs[0:npro-1]
			
      end
'biglist': status.listsel=ev.index
'clus_frac':begin
	  widget_control, ev.id, get_value=val
	  status.clust_frac=val
	end
'view_param':begin
	if status.listsel GE 0 then begin
	spawn, 'echo $SLUG_DIR', dir
	openr, lun, dir+'/output/'+proc[status.listsel].modelname+'.param', /get_lun
	dum=''
	dumarr=''
	while ~EOF(lun) do begin
	  readf, lun, dum
	  dumarr=[dumarr, dum]
	endwhile
	close, lun
	rds_popup, status.tlb, text=dumarr
	endif
	end
'copy':begin
	  if status.listsel GE 0 then begin
	  spawn, 'echo $SLUG_DIR', dir
	  parse_param, dir+'/output/'+proc[status.listsel].modelname+'.param'
	  endif
	end

'make_sfh':begin
	   mksfh, status.tlb, status.maxtime
	   widget_control, status.tlb, time=0.5
	end
'cmag_on':begin
	if total(status.fluxes GT 0) GE 1.9  then begin
	widget_control, status.cmagadd, sensitive=1
	status.cmagson=1
	endif else widget_control, status.cmagoff, set_button=1
	end
'cmag_off':begin
        widget_control, status.cmagadd, sensitive=0
        status.cmagson=-1
        end

'cmagadd':begin
	cmagadd, status.tlb, status
	widget_control, status.tlb, time=0.5
	end

;	end
'kill':begin
	if status.listsel GE 0 then begin
	proc[status.listsel].obridge->abort
	obj_destroy, proc[status.listsel].obridge

	proc[status.listsel].status=-2
	status.list_of_procs[status.listsel]=proc[status.listsel].modelname+$
                                                        '     Started on '+proc[status.listsel].start_time+$
                                                        '     Done...'
	npro=n_elements(proc)
	widget_control, status.big_list, set_value=status.list_of_procs[0:npro-1]
	endif
	end

'top_menu':begin
	  case ev.value of
	   'Quit':uvalue='quit'
	   'Open':begin
		    res=rds_fileselect(theobject, base=status.tlb,$
					 filter='*.param')
		    if keyword_set(res) then parse_param, res
		  end
	   else: 
	  endcase
	end
'tracks':begin
	status.trackchoice=*(ev.selection)
	if strmatch(status.trackchoice, 'gen*') then $
		status.fehnames= ['0.001','0.004','0.008','0.020', '0.040'] $
	else    status.fehnames=['0.0004','0.004','0.008','0.020', '0.050'] 
	fehlistid->setvalues, status.fehnames
	end
'slope_imf':begin
	widget_control, ev.id, get_value=slp
	status.imf_slope=slp
	print, status.imf_slope
	end
'clusout_yes':status.outcluster='yes'
'clusout_no':status.outcluster='no'
'imf_yes':status.imfout='yes'
'imf_no':status.imfout='no'
else: if keyword_set(uvalue) then print, uvalue
endcase

widget_control, status.runbtn, sensitive=total(status.fluxes GT 0) GT 0.9

if strmatch(uvalue, 'imf') then begin
if strmatch(*(ev.selection), '*SLOPE*') then begin
	widget_control, status.slopefield, sensitive=1 
	widget_control, status.slopefield_lbl, sensitive=1 
endif else begin
	widget_control, status.slopefield, sensitive=0 
	widget_control, status.slopefield_lbl, sensitive=0 
endelse
if strmatch(*(ev.selection), '*IGIMF*') then $
    widget_control, status.cmfmaxbtnlbl, set_value='Max Cluster Interval' else $
	widget_control, status.cmfmaxbtnlbl, set_value='Max Cluster Mass: '

endif

;if keyword_set(uvalue) then help, uvalue
	;   while keyword_set(sfh_final_name) EQ 0 do begin
;		help, sfh_final_name
;		
;	   endwhile
;;	   res=sfh_final_name
;	   if strmatch(res, 'bad_exit_123456') EQ 0 then begin
;	     status.sfr=-1
;	     status.sfh=res
;	   endif
;	   gui_refresh


IF (TAG_NAMES(ev, /STRUCTURE_NAME) EQ 'WIDGET_TIMER') then begin
	widget_control, ev.top, timer=0.1
	if keyword_set(proc) then begin
	  change=0
	  for i=0, n_elements(proc)-1 do begin
	     npro=n_elements(proc)
	     if proc[i].status GT 0 then proc[i].status=proc[i].obridge->status() 
	     if proc[i].status EQ -1 then proc[i].status=((proc[i].obridge->status() EQ 0)?-2:-1) 
	     if proc[i].status EQ 0 then begin
;		obj_destroy, proc[i].obridge
		status.list_of_procs[i]=proc[i].modelname+$
						'     Started on '+proc[i].start_time+$
						'     Parsing...'
		change=1
		proc[i].status=-1
		proc[i].obridge->execute, 'read_slug, "'+proc[i].modelname+'"'
	     endif
	     if proc[i].status EQ -2 then begin
		obj_destroy, proc[i].obridge
		status.list_of_procs[i]=proc[i].modelname+$
							'     Started on '+proc[i].start_time+$
							'     Done...'
		change=1
		proc[i].status=-3
	     endif
	
             if keyword_set(change) then $
			widget_control, status.big_list, set_value=status.list_of_procs[0:npro-1]
	  endfor
	endif
	if keyword_set(sfh_final_name) then begin
	  if strmatch(sfh_final_name, 'bad_exit_123456') EQ 0 then begin
            status.sfr=-1
            status.sfh=sfh_final_name
          endif
          gui_refresh
	  sfh_final_name=''
	endif

	
endif

widget_control, status.cmagon, sensitive=total(status.fluxes GT 0) GT 1.9
;if strmatch(tag_names(ev, /structure_name), '*TIMER*') EQ 0 then help, ev, /st

if strmatch(uvalue, 'help*') then help_menu, uvalue
if strmatch(uvalue, 'quit') then begin
	widget_control, ev.top, /destroy
	if keyword_Set(proc) then  for i=0, n_elements(proc)-1 do begin
		if proc[i].status LT 0 then continue
		proc[i].obridge->abort
		obj_destroy, proc[i].obridge
		endfor
endif
end

;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
pro slug
common slugs, status
common btns, imfbtn, fehbtn
common refs, fehlistid, sedlistid, windlistid, trbtn

status={tlb:0L, big_list:0L, imfnames:['KROUPA', 'CHABRIER', 'SALPETER', 'IGIMF',$
		'SLOPE'], imfind:0L, imflist:0L,$
		fehnames:['0.0004','0.004','0.008','0.020','0.050'],fehind:0L, fehlist:0L, $
		menu_ids:lonarr(25), cmagadd:0L, $
		imfbtn:0L, fehbtn:0L, drawbtns:lonarr(2), $
		cmfmaxbtn:0L, cmfmaxbtnlbl:0L,$
		cmfminbtn:0L, cmfslopebtn:0L, sfhbtn:0L, outnamebtn:0L,$
		timestepbtn:0L, maxtimebtn:0L, fluxesbtn:lonarr(17), $
		fluxes:lonarr(17)-1, cmagon:0L, cmagoff:0L,$
		timestep:'1E6', maxtime:'3E6', sfr:'1', sfh:'mysfh.txt', imfchoice:'KROUPA', $,$
		wind_choice:'maedr',$
		fehchoice:'0.020', modelname:'test1', maxclustermass:'1E7',$
		minclustermass:'20',$
		slopecmf:'-2', drawchoice:'RANDOM', flux_choice:'NUV,FUV', $
		colorchoice:'FUV-NUV', binflux:'200', bincolor:'200', maxcolor:'50',$
		mincolor:'-50', maxflux:'50', minflux:'-50', list_of_procs:strarr(1000), time_of_check:0.,$
		listsel:-1L, cmagson:-1, imfout:'no', outcluster:'no',$
		trnames:['padagb', 'padstd', 'genhi', 'genstd'], trackchoice:'padagb',$
		windchoice:'maedr', sedchoice:'lej+smi', slopefield:0L, slopefield_lbl:0L,$
		imf_slope:'-2.35', wind_names:['maedr', 'elson', 'emp', 'theor'], $
		sed_names:['planck', 'lej', 'lej+sch', 'lej+smi', 'pau+smi'],$
		runbtn:0L, clust_frac:'1.0', seed:'0', seedbtn:0L, coutbtnn:0L,$
		coutbtny:0L, ioutbtnn:0L, ioutbtny:0L, clusfracbtn:0L}

status.tlb=widget_base(title='SLUG: Stochastically Lighting Up Galaxies', $
	xsize=1034, ysize=768, /column, app_mbar=top_menu)

;Make the pull-down menu
tmp_struct = {cw_pdmenu_s, flags:0, name:''}

top_menu_desc = [ $
                  {cw_pdmenu_s, 1, 'File'}, $ ; file menu ;flags 1 starts a menu
  ;                {cw_pdmenu_s, 0, 'Setup'}, $		;0 is an entry
                  {cw_pdmenu_s, 0, 'Open'},  $		;2 ends a menu
                  {cw_pdmenu_s, 2, 'Quit'}];, $
;		  {cw_pdmenu_s, 1, 'Help'},$
;                  {cw_pdmenu_s, 2, 'Example'}];,$
;		  {cw_pdmenu_s, 1, 'How to Cite'},$
 ;                 {cw_pdmenu_s, 2, 'Explanation'} ]

top_menu = cw_pdmenu(top_menu, top_menu_desc, $
                     ids = status.menu_ids, $
                     /mbar, $
                     /help, $
                     /return_name, $
                     uvalue = 'top_menu')
qval=' ? '
row1=widget_base(status.tlb, /row)
col1=widget_base(row1, /col)
topcol1=widget_base(col1, col=1, /frame)
lbl=widget_label(topcol1, value='Physical Properties', /align_center)
row00=widget_base(topcol1, /row)
imfbtn=fsc_droplist(row00, value=status.imfnames, uvalue='imf', title='IMF Type         ')
btn=widget_button(row00, value=qval, uvalue='help_imf')


row00=widget_base(topcol1, /row)
status.slopefield_lbl=widget_label(row00, $
	value='IMF Slope         ', sensitive=0)
status.slopefield=widget_text(row00, /all, $
	uvalue='slope_imf', sensitive=0, value='-2.35',$
	/editable)
btn=widget_button(row00, value=qval, uvalue='help_imfslope')

row00=widget_base(topcol1, /row)
trbtn=fsc_droplist(row00, value=status.trnames, uvalue='tracks', title='Tracks           ')
btn=widget_button(row00, value=qval, uvalue='help_tracks')

row00=widget_base(topcol1, /row)
fehlistid=fsc_droplist(row00, value=status.fehnames, uvalue='feh', title='Metallicity      ')
fehlistid->setselection, '0.020'
btn=widget_button(row00, value=qval, uvalue='help_feh')

row00=widget_base(topcol1, /row)
sedlistid=fsc_droplist(row00, value=status.sed_names, uvalue='sed', title='SED Model        ')
sedlistid->setselection, 'lej+smi'
btn=widget_button(row00, value=qval, uvalue='help_sed')

row00=widget_base(topcol1, /row)
windlistid=fsc_droplist(row00, value=status.wind_names, uvalue='wind', title='Wind Model       ')
windlistid->setselection, 'maedr'
btn=widget_button(row00, value=qval, uvalue='help_wind')

;topcol2=widget_base(col1, col=1, /frame)
topcol2=topcol1
;lbl=widget_label(topcol2, value='Star Formation Properties', /align_center)


row00=widget_base(topcol2, /row)
status.clusfracbtn=$
   cw_field(row00, title='Cluster Fraction:', value='1.0', /all, uvalue='clus_frac')
btn=widget_button(row00, value=qval, uvalue='help_clusfrac')

row00=widget_base(topcol2, /row)
;status.cmfmaxbtn=cw_field(row00, title='Max Cluster Mass:', value='1E7', /all, uvalue='maxmass')
status.cmfmaxbtnlbl=widget_label(row00, value='  Max Cluster Mass:  ')
status.cmfmaxbtn=widget_text(row00, value='1E7', /all, /editable, uvalue='maxmass',$
	 xsize=6)
btn=widget_button(row00, value=qval, uvalue='help_maxmass')

row00=widget_base(topcol2, /row)
status.cmfminbtn=cw_field(row00, title='Min Cluster Mass:', value='20', /all, uvalue='minmass')
btn=widget_button(row00, value=qval, uvalue='help_minmass')
row00=widget_base(topcol2, /row)
status.cmfslopebtn=cw_field(row00, title='CMF Slope        ', value='-2', /all, uvalue='cmfslope')
btn=widget_button(row00, value=qval, uvalue='help_cmfslope')

read_jpeg, '$SLUG_DIR/slug3.jpeg', slugimage

col00=widget_base(row1, /col)
logo=widget_draw(col00, xsize=336, ysize=221, uvalue='logo')
col0=widget_base(col00, /col, /frame)
lbl=widget_label(col0, /align_center, value='Simulation Properties')


row00=widget_base(col0, /row)
status.timestepbtn=cw_field(row00, title='Timestep:        ', value='1E6', /all, uvalue='timestep')
btn=widget_button(row00, value=qval, uvalue='help_timestep')
row00=widget_base(col0, /row)
status.maxtimebtn=cw_field(row00, title='Max Time:        ', value='3E6', /all, uvalue='maxtime')
btn=widget_button(row00, value=qval, uvalue='help_maxtime')

;row00=widget_base(topcol2, /row)
row00=widget_base(col0, /row)
status.sfhbtn=cw_field(row00, title='SFH:             ', value='1', /all, uvalue='sfh')
btn=widget_button(row00, value='Make', uvalue='make_sfh')
btn=widget_button(row00, value=qval, uvalue='help_sfh')

row00=widget_base(col0, /row)
status.seedbtn=cw_field(row00, title='Seed:            ', value='0', /all, uvalue='seed')
btn=widget_button(row00, value=qval, uvalue='help_seed')


drawrow=widget_base(col0, /row)
lbl=widget_label(drawrow, value='Draw Type:       ')
base0=widget_base(drawrow, /exclusive, /row)
status.drawbtns[0]=widget_button(base0, value='Random', uvalue='random')
status.drawbtns[1]=widget_button(base0, value='Sequential', uvalue='sequential', sensitive=0)
btn=widget_button(drawrow, value=qval, uvalue='help_draw')

topcol3=widget_base(row1, /col, /frame)
lbl=widget_label(topcol3, value='Output', /align_center)
drawrow=widget_base(topcol3, /col, /frame)
row00=widget_base(drawrow, /row, /align_center)
lbl=widget_label(row00, value='Fluxes:')
btn=widget_button(row00, value=qval, uvalue='help_fluxes')
base0=widget_base(drawrow, /nonexclusive, col=5)
status.fluxesbtn[0]=widget_button(base0, value='NUV', uvalue='nuv')
status.fluxesbtn[1]=widget_button(base0, value='FUV', uvalue='fuv')
status.fluxesbtn[2]=widget_button(base0, value='BOL', uvalue='bol')
status.fluxesbtn[3]=widget_button(base0, value='J', uvalue='j')
status.fluxesbtn[4]=widget_button(base0, value='H', uvalue='h')
status.fluxesbtn[5]=widget_button(base0, value='K', uvalue='k')
status.fluxesbtn[6]=widget_button(base0, value='SDSSu', uvalue='SDSSu')
status.fluxesbtn[7]=widget_button(base0, value='SDSSg', uvalue='SDSSg')
status.fluxesbtn[8]=widget_button(base0, value='SDSSr', uvalue='SDSSr')
status.fluxesbtn[9]=widget_button(base0, value='SDSSi', uvalue='SDSSi')
status.fluxesbtn[10]=widget_button(base0, value='SDSSz', uvalue='SDSSz')
status.fluxesbtn[11]=widget_button(base0, value='johnsonU', uvalue='johnsonU')
status.fluxesbtn[12]=widget_button(base0, value='johnsonB', uvalue='johnsonB')
status.fluxesbtn[13]=widget_button(base0, value='johnsonV', uvalue='johnsonV')
status.fluxesbtn[14]=widget_button(base0, value='johnsonR', uvalue='johnsonR')
status.fluxesbtn[15]=widget_button(base0, value='johnsonI', uvalue='johnsonI')
status.fluxesbtn[16]=widget_button(base0, value='QH0', uvalue='QH0')


drawrow=widget_base(topcol3, /col, /frame)
row00=widget_base(drawrow, /row, /align_center)
lbl=widget_label(row00, value='Color Mag Diagrams:')
base0=widget_base(row00, /exclusive, /row)
status.cmagon=widget_button(base0, value='On', uvalue='cmag_on')
status.cmagoff=widget_button(base0, value='Off', uvalue='cmag_off')
btn=widget_button(row00, value=qval, uvalue='help_colormag')
row00=widget_base(drawrow, /row, /align_center)
status.cmagadd=widget_button(row00, value='Add/Remove a CMD', uvalue='cmagadd', sensitive=0)
btn=widget_button(row00, value=qval, uvalue='help_addcolormag')

row00=widget_base(topcol3, /row)
lbl=widget_label(row00, value='Cluster Output?')
clusout=widget_base(row00, /row, /exclusive)
status.coutbtnn=widget_button(clusout, value='No', uvalue='clusout_no')
widget_control, status.coutbtnn, /set_button
status.coutbtny=widget_button(clusout, value='Yes', uvalue='clusout_yes')
btn=widget_button(row00, value=qval, uvalue='help_clusout')

row00=widget_base(topcol3, /row)
lbl=widget_label(row00, value='IMF Output?    ')
clusout=widget_base(row00, /row, /exclusive)
status.ioutbtnn=widget_button(clusout, value='No', uvalue='imf_no')
widget_control, status.ioutbtnn, /set_button
status.ioutbtny=widget_button(clusout, value='Yes', uvalue='imf_yes')
btn=widget_button(row00, value=qval, uvalue='help_imfout')


row00=widget_base(topcol3, /row)
status.outnamebtn=cw_field(row00, title='Model Name:      ', value=status.modelname, /all, uvalue='outname')
btn=widget_button(row00, value=qval, uvalue='help_name')


row2=widget_base(status.tlb, /row, /align_center)
status.runbtn=widget_button(row2, value='Run Process', uvalue='run')
btn1=widget_button(row2, value='View Param File', uvalue='view_param')
btn1=widget_button(row2, value='Copy Process', uvalue='copy')
btn1=widget_button(row2, value='Grid Process', uvalue='grid', sensitive=0)
btn1=widget_button(row2, value='Kill Process', uvalue='kill', sensitive=0)
btn=widget_button(row2, value=qval, uvalue='help_running')


status.big_list=widget_list(status.tlb, scr_ysize=200, uvalue='biglist')


lbl=widget_label(status.tlb, /align_center, value='da Silva, Fumagalli, & Krumholz')

widget_control, status.tlb, /realize
widget_control, logo, get_value=winid
wset, winid
tv, slugimage, true=1
widget_control, status.tlb, timer=0.1
widget_control, status.drawbtns[0], /set_button
widget_control, status.cmagoff, /set_button

xmanager, 'slug', status.tlb, /no_block
end
